﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DotLineRender : MonoBehaviour {
    public Transform startPivot;
    public Transform middle;
    public Transform endPivot;
    public LineRenderer render;
    public float CurvedParamater;
    public float flowSpeed;
    public float dotDensity;
    public bool isRender;


    public void ResetPos(Vector3 start,Vector3 end)
    {
        startPivot.position = start;
        endPivot.position = end;
        middle.position = new Vector3((start.x + end.x) * 0.5f,
                (start.y + end.y) * 0.5f +
                Mathf.Clamp(CurvedParamater*Mathf.Log((Vector3.ProjectOnPlane(start,Vector3.up)- Vector3.ProjectOnPlane(end, Vector3.up)).magnitude/ CurvedParamater),0,float.MaxValue)
            , (start.z + end.z) * 0.5f);
    }
	
	// Update is called once per frame
	void Update () {
        ResetPos(startPivot.position, endPivot.position);
        render.material.SetFloat("_Speed", flowSpeed);
        float repeatCount = dotDensity * (startPivot.position - endPivot.position).magnitude;
        //render.material.SetFloat("_RepeatCount", repeatCount);
        


        if (isRender) render.enabled = true;
        else render.enabled = false;



    }

}
